<?php
  #--------------------------------------------------
  # ALL INCLUDES + STANDARD-VALUES
  #--------------------------------------------------
  include_once("include/config.inc");
  include_once("include/template.inc");
  include_once("include/class.db.php5");
  include_once("include/class.tools.php5");
  $svo = new db("svoptik");
  $tools = new tool();

  include_once("include/global_fix_extern.inc");

  #--------------------------------------------------
  # CREATE TEMPLATE
  #--------------------------------------------------
  $t = new Template("templates", "keep");
  $t->set_file(array("page"  => "svoptik.tpl",
                     "login" => "login.tpl",
                     "ticker" => "ticker.tpl",
                     "navi"  => "navi.tpl"));
  #--------------------------------------------------


  #--------------------------------------------------
  # CREATE NAVIGATION RIGHT
  #--------------------------------------------------
  $links = "";
  $url[0] = array("URL" => "javascript:;", "ONCLICK" => "onClick=\"javascript:window.open('new_member.php5','','width=400,height=563,locationbar=no,scrollbars=no,statusbar=no,resizable=no')\"", "URL-TEXT" => "Anmelden");
  $url[1] = array("URL" => "javascript:;", "ONCLICK" => "onClick=\"javascript:window.open('lost_pw.php5','','width=400,height=563,locationbar=no,scrollbars=no,statusbar=no,resizable=no')\"", "URL-TEXT" => "Passwort vergessen?");

  for ($i=0; $i<count($url); $i++) {
     $links .= "
        <tr height=\"15\">
			<td valign=\"top\"><img src=\"standard/spacer.gif\" width=\"20\" height=\"15\" border=\"0\" alt=\"\"></td>
			<td valign=\"top\"><a href=\"".$url[$i]['URL']."\" ".$url[$i]['ONCLICK']." class=\"sitenav\">".$url[$i]['URL-TEXT']."</a></td>
			<td valign=\"top\"><img src=\"standard/spacer.gif\" width=\"20\" height=\"15\" border=\"0\" alt=\"\"></td>
		</tr>
		<tr height=\"15\">
            <td colspan=\"3\"><img src=\"standard/spacer.gif\" width=\"20\" height=\"15\" border=\"0\" alt=\"\"></td>
		</tr>
       ";
  }
  $t->set_var(array("LINKS" => $links, "BANNER" => $banner));
  $right_nav = $t->parse("","navi", true);
  #--------------------------------------------------


 #--------------------------------------------------
# CREATE ALL-TIME SAME THINGS
#--------------------------------------------------
include_once ("include/sameThings.php5");

  #--------------------------------------------------



  #--------------------------------------------------
  # CREATE CONTENT "LOGIN MEMBERAREA"
  #--------------------------------------------------
  global $send;
  $msg = "";
  $auth = 0;


  @session_destroy();
  @session_unregister("usr_id");
  @session_unregister("usr_priv");
  

  if ($send) { 
      // Authorisierung
      $usr_data = $svo->readRecordset("select * from ".$table['User']." where usr_nick='".$usr_name."' &&usr_act_status=1;");
      if ($usr_name == $usr_data['usr_nick'] && $usr_passwd == $usr_data['usr_passwd']) $auth = 1;
      else {
          $auth = 0;
          $msg = "
          <tr>
              <td colspan=\"2\" class=\"text\" valign=\"top\" align=\"center\"><br><b>Fehler bei der Authorisierung.</b><br><br>Bitte kontrolliere die Eingaben bei Usernamen und Passwort</td>
          </tr>
      ";
      }

      if ($auth) {
          session_start();
	      $_SESSION["usr_priv"]=$usr_data["usr_priv"];
	      $_SESSION["usr_id"]=$usr_data["usr_id"];
	      $_SESSION["usr_last_login"]=$usr_data["usr_last_login"];
	      session_register("usr_priv", "usr_id", "usr_last_login");
          $svo->doSQL("update ".$table['User']." set usr_last_login='".date("Y-m-d H:i:s")."' where usr_id=".$usr_id."");
      }
  }

  if (!$auth) {
      $t->set_var(array("NAME" => $usr_name,
                        "MESSAGE" => $msg));
      $content = $t->parse("","login", true);
  } else {
      $content = "
      <script language=\"javascript\">
      <!--
          window.location.replace('member/index.php5');
      //-->
      </script>
      <p width=\"80%\" align=\"center\" class=\"text\"><br><br>F&uuml;r den Fall, da&szlig; die automatische Weiterleitung nicht funktioniert klicke bitte <a href=\"member/index.php\" class=\"news\" target=\"_self\" onClick=\"\">hier</a> um in die Member-Area zu gelangen</p>
      ";
  }

  #--------------------------------------------------


  #--------------------------------------------------
  # PARSE & OUTPUT
  #--------------------------------------------------
  $t->set_var(array("sitenav" => "MEMBERAREA -> LOGIN",
                    "ticker" => $ticker,
                    "content" => $content,
                    "navi"    => $right_nav));

  $t->parse("ALL", "page", true);
  $t->p("ALL");
?>
